yjx.controller('clientListController', ['$rootScope', '$scope', '$timeout', '$fetch', 'modalService', '$timeout', '$state', '$init', function ($rootScope, $scope, $timeout, $fetch, modalService, $timeout, $state, $init) {
    $init.title("客户列表")
    var api = '/customer/list';
    /**获取客户列表 */
    function getClientList() {
        $fetch.fetch(
            api,
            {
                params: {
                   type:1,
                },
                cache: false
            }
        ).then(function (data) {
            $timeout(function(){
                $scope.clientList = data;
                // buildSwiper();
            })
        }).catch(function (e) {
            modalService.mainMsgError(e.msg)
        })
    }
    function getUnClientList() {
        $fetch.fetch(
            api,
            {
                params: {
                   type:0,
                },
                cache: false
            }
        ).then(function (data) {
            $timeout(function(){
                $scope.unclientList = data;
                // buildSwiper();
            })
        }).catch(function (e) {
            modalService.mainMsgError(e.msg)
        })
    }
    if($rootScope.userId){
        getClientList();
        getUnClientList();
       
    }
    $timeout(function(){
        buildSwiper();
    },500)
    /**swiper */
    $scope.tabList = [{ id: 1, name: '已成交客户' }, { id: 2, name: '意向客户' }];
     $scope.curTab  = $scope.tabList[0];
    var tabList, curSwiper;
    var width = document.body.offsetWidth;
    function buildSwiper() {
        tabList = new Swiper('#tabList', {
            slidesPerView: 2,
            slideToClickedSlide: true,
        });
        curSwiper = new Swiper('#cltSwiper', {
            direction: 'horizontal',
            // noSwiping : true,
            slider: width,
            on: {
                slideNextTransitionStart: function () {
                    tabList.slideTo(curSwiper.activeIndex)
                    $timeout(function () {
                        $scope.curTab = $scope.tabList[curSwiper.activeIndex];
                    })
                },
                slidePrevTransitionStart: function () {
                    tabList.slideTo(curSwiper.activeIndex - 1)
                    $timeout(function () {
                        $scope.curTab = $scope.tabList[curSwiper.activeIndex];
                    })
                }
            }
        })
    }

    $scope.tabSelect = function (item, index) {
        $scope.curTab = item;
        curSwiper.slideTo(index, 500);
        // $timeout(function(){ curSwiper.slideTo(item.id - 1, 500);})
    }
   
    /**添加客户*/
     /*新增客户信息*/
    $scope.addInfo = function () {
        $scope.showInfo = true;
        $state.go('clientList.info');
        $scope.editClient = {sex:'男'};
    }
    /**测试数据 */
   
    

}])